#include <algorithm>
#include <cstdio>
#include <queue>

const int N = 500005, inf = 0x3f3f3f3f;
int n, m, hash[N << 1], ans = inf;
std::queue<int> q;

struct Node {
  int val, tag;
} tr[N << 3];

struct Segment {
  int l, r;
  inline bool operator<(const Segment &rhs) const { return r - l < rhs.r - rhs.l; }
} seg[N];

inline void pushdown(int x) {
  static int ls, rs;
  if (tr[x].tag != 0) {
    ls = x << 1, rs = x << 1 | 1;
    tr[ls].tag += tr[x].tag;
    tr[rs].tag += tr[x].tag;
    tr[ls].val += tr[x].tag;
    tr[rs].val += tr[x].tag;
    tr[x].tag = 0;
  }
}

inline void pushup(int x) { tr[x].val = std::max(tr[x << 1].val, tr[x << 1 | 1].val); }

void modify(int x, int l, int r, int L, int R, int v) {
  if (L <= l && r <= R) { return tr[x].val += v, tr[x].tag += v, void(); }
  int mid = (l + r) >> 1;
  pushdown(x);
  if (L <= mid) modify(x << 1, l, mid, L, R, v);
  if (mid < R) modify(x << 1 | 1, mid + 1, r, L, R, v);
  pushup(x);
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("P1712 [NOI2016]区间.in", "r", stdin);
  freopen("P1712 [NOI2016]区间.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i)
    scanf("%d%d", &seg[i].l, &seg[i].r), hash[++*hash] = seg[i].l,
                                         hash[++*hash] = seg[i].r;
  std::sort(hash + 1, hash + *hash + 1);
  *hash = std::unique(hash + 1, hash + *hash + 1) - hash - 1;
  std::sort(seg + 1, seg + n + 1);
  for (int i = 1; i <= n; ++i) {
    seg[i].l = std::lower_bound(hash + 1, hash + *hash + 1, seg[i].l) - hash;
    seg[i].r = std::lower_bound(hash + 1, hash + *hash + 1, seg[i].r) - hash;
    modify(1, 1, *hash, seg[i].l, seg[i].r, 1);
    q.push(i);
    while (tr[1].val >= m) {
      ans = std::min(ans, hash[seg[i].r] - hash[seg[i].l] - hash[seg[q.front()].r] +
                              hash[seg[q.front()].l]);
      int tmp = q.front();
      q.pop();
      modify(1, 1, *hash, seg[tmp].l, seg[tmp].r, -1);
    }
  }
  if (ans == inf) puts("-1");
  else
    printf("%d", ans);
  return 0;
}